---
category: Misc
created: '2021-02-20'
title: Convert 3 digits color to 6 digits color
updated: '2021-10-13'
---

**JavaScript version**

```js toFullHexColor.js
const toFullHexColor = (color) =>
    `#${(color.startsWith('#') ? color.slice(1) : color)
        .split('')
        .map((c) => `${c}${c}`)
        .join('')}`;
```

**TypeScript version**

```ts toFullHexColor.ts
const toFullHexColor = (color: string): string =>
    `#${(color.startsWith('#') ? color.slice(1) : color)
        .split('')
        .map((c) => `${c}${c}`)
        .join('')}`;
```

**Examples**

```js examples.js
toFullHexColor('123'); // '#112233'
toFullHexColor('#123'); // '#112233'
toFullHexColor('#abc'); // '#aabbcc'
```
